//
//  UIButton+Extonsion.swift
//  swiftWeibo
//
//  Created by apple on 15/12/9.
//  Copyright © 2015年 张智伟. All rights reserved.
//

import UIKit

extension UIButton{
    
    /// 便利构造函数
    ///
    /// - parameter imageName:     图片名称
    /// - parameter backImageName: 背景图片名称
    ///
    /// - returns: UIButton
    convenience init(imageName: String,backImageName: String){
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted" ), forState: UIControlState.Highlighted)
        //设置fram 会根据背景图片的大小自动调整大小
        sizeToFit()

    }
    /// 便利构造函数
    ///
    /// - parameter title:
    /// - parameter color:
    /// - parameter imageName:
    ///
    /// - returns: UIButton
    convenience init(title: String,color: UIColor,imageName: String){
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        
    }
}